using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Volo.Abp.AspNetCore.Mvc;
using AuthService.Services;

namespace AuthService.Controllers;

/// <summary>
/// 认证授权控制器
/// </summary>
[ApiController]
[Route("api/auth")]
public class AuthController : AbpControllerBase
{
    private readonly IAuthService _authService;

    public AuthController(IAuthService authService)
    {
        _authService = authService;
    }

    /// <summary>
    /// 用户登录
    /// </summary>
    [HttpPost("login")]
    public async Task<LoginResultDto> LoginAsync([FromBody] LoginRequestDto input)
    {
        return await _authService.LoginAsync(input);
    }

    /// <summary>
    /// 用户登出
    /// </summary>
    [HttpPost("logout")]
    public async Task LogoutAsync([FromBody] LogoutRequestDto input)
    {
        await _authService.LogoutAsync(input);
    }

    /// <summary>
    /// 刷新Token
    /// </summary>
    [HttpPost("refresh-token")]
    public async Task<RefreshTokenResultDto> RefreshTokenAsync([FromBody] RefreshTokenRequestDto input)
    {
        return await _authService.RefreshTokenAsync(input);
    }

    /// <summary>
    /// 验证Token
    /// </summary>
    [HttpPost("validate-token")]
    public async Task<TokenValidationResultDto> ValidateTokenAsync([FromQuery] string token)
    {
        return await _authService.ValidateTokenAsync(token);
    }

    /// <summary>
    /// 获取Token信息
    /// </summary>
    [HttpGet("token-info")]
    public async Task<TokenInfoDto> GetTokenInfoAsync([FromQuery] string token)
    {
        return await _authService.GetTokenInfoAsync(token);
    }

    /// <summary>
    /// 获取用户上下文
    /// </summary>
    [HttpGet("user-context")]
    public async Task<UserContextDto> GetUserContextAsync([FromQuery] string token)
    {
        return await _authService.GetUserContextAsync(token);
    }

    /// <summary>
    /// 检查用户权限
    /// </summary>
    [HttpGet("has-permission")]
    public async Task<bool> HasPermissionAsync([FromQuery] string userId, [FromQuery] string permission)
    {
        return await _authService.HasPermissionAsync(userId, permission);
    }

    /// <summary>
    /// 获取用户权限列表
    /// </summary>
    [HttpGet("user-permissions")]
    public async Task<List<string>> GetUserPermissionsAsync([FromQuery] string userId)
    {
        return await _authService.GetUserPermissionsAsync(userId);
    }

    /// <summary>
    /// 获取用户角色列表
    /// </summary>
    [HttpGet("user-roles")]
    public async Task<List<string>> GetUserRolesAsync([FromQuery] string userId)
    {
        return await _authService.GetUserRolesAsync(userId);
    }

    /// <summary>
    /// 重置密码
    /// </summary>
    [HttpPost("reset-password")]
    public async Task ResetPasswordAsync([FromBody] ResetPasswordRequestDto input)
    {
        await _authService.ResetPasswordAsync(input);
    }

    /// <summary>
    /// 修改密码
    /// </summary>
    [HttpPost("change-password")]
    public async Task ChangePasswordAsync([FromBody] ChangePasswordRequestDto input)
    {
        await _authService.ChangePasswordAsync(input);
    }
}